{% extends 'ajax/base.html' %}
{% block content %}

<ul>
    <li>账号:<input type="text" value="" name="username" id="txtUsername" /> </li>
    <li>密码:<input type="password" value="" name="password" id="txtPassword" /> </li>
    <li><input type="button" value="登录" id="btnLogin"></li>
</ul>
<br />
<div id="divError">

</div>
{% endblock %}

{% block js %}
<script type="text/javascript">
$("#btnLogin").click(function(){
    var username = $("#txtUsername").val();
    var password = $("#txtPassword").val();

    if(!username || !password)
    {
          alert("账号或密码不能为空");
          return;
    }
    $.post("{% url 'users:ajax_auth_login' %}", {"username": username, 'password': password}, function(datas){
        if(datas.result == 1){
            location.href = datas.next_url;
        }else if(datas.result == -1){
            $("#divError").html(datas.error_html);
        }
        else{
            alert(datas.error_message);
        }
    });

})
</script>
{% endblock %}